package com.linglan.modules.doctor.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.linglan.common.enums.HotSearchType;
import com.linglan.modules.doctor.dao.BizHosearchDao;
import com.linglan.modules.doctor.dto.result.HotSearchResult;
import com.linglan.modules.doctor.entity.BizHosearch;
import com.linglan.modules.doctor.service.BizHosearchService;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;

/**
 * 热门搜索表(BizHosearch)表服务实现类
 *
 * @author pjx
 * @since 2025-06-05 21:14:15
 */
@Service("bizHosearchService")
public class BizHosearchServiceImpl extends ServiceImpl<BizHosearchDao, BizHosearch> implements BizHosearchService {

    /**
     * 查询热门搜索
     *
     * @return
     */
    @Override
    public List<HotSearchResult> findHotSearch() {
        LambdaQueryWrapper<BizHosearch> queryWrapper = Wrappers.lambdaQuery();
        queryWrapper.eq(BizHosearch::getIsDeleted, 0);
        queryWrapper.orderByAsc(BizHosearch::getSeq);
        List<BizHosearch> list = this.list(queryWrapper);
        if (CollectionUtils.isNotEmpty(list)) {
            return list.stream().map(item -> {
                HotSearchResult result = new HotSearchResult();
                result.setId(item.getId());
                result.setType(HotSearchType.getByCode(item.getHotType()));
                result.setObjId(item.getObjId());
                result.setSeq(item.getSeq());
                return result;
            }).collect(Collectors.toList());
        }
        return Collections.emptyList();
    }
}

